<template>
  <div>
    <form class="mui-input-group">

      <div class="mui-button-row">
        <button 
          type="button" 
          class="mui-btn mui-btn-primary" 
          @click="denglu">登录</button>
      </div>
    </form>
  </div>
</template>

<script>
import Qs from 'qs'
export default {
  data() {
    return {
      ts: this.newStore()
    }
  },
  // mounted() {
  //   const query = Qs.parse(window.location.search.substring(1)) //http://hg.eke88.com
  //   // eslint-disable-next-line prefer-destructuring
  //   console.log(window.location)
  //   const code = query.code
  //   if (config.MODE == 'dev') {
  //     this.getUserInfoByDev()
  //     return
  //   } else {
  //     if (code && code != '') {
  //       // 从微信转回，进行服务器登录
  //       this.doLogin(code)
  //       return
  //     }
  //   }

  //   // // 判断登录
  //   this.getWxCode()
  // },
  methods: {
    denglu() {
      localStorage.setItem('token', 'abc')
      mui.toast('登录成功！', { duration: '1000', type: 'div' })
      this.$router.push({
        name: 'fhome'
      })
    },
    // 模拟接口
    // getmoni() {
    //   this.$router.push({ name: 'login' })
    // },
    getWxCode() {
      const wxLoginUrl =
        'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe2bb8099c417351d&redirect_uri=http://hg.eke88.com&response_type=code&scope=snsapi_userinfo#wechat_redirect'

      // 改成ajax试试
      window.location = wxLoginUrl

      console.info('wxLoginUrl:' + wxLoginUrl)
      this.spost(this.ts, wxLoginUrl).then(response => {
        console.info(response)
      })
    },
    doLogin(code) {
      const res = {
        code: code
      }
      this.sget(this.ts, '/Register/getWeixinCode', res).then(ts => {
        if (ts.d.flag == '200') {
          console.log(ts.d.data)
          localStorage.setItem('token', ts.d.data.token)
          console.log(localStorage.getItem('token'))
          localStorage.setItem('identity', ts.d.data.identity)
          this.$router.push({ name: 'ephome' })
        }
      })
      console.log('doLogin', code)
    },
    getUserInfoByDev() {
      this.$router.push({ name: 'login' })
    }
  }
}
</script>

<style>
</style>
